
import time


class Environ:
    def __init__(self, *args):
        self.environ = dict()
        for a in args:
            if isinstance(a, dict):
                for k in a:
                    self.set(k, a[k])

    def set(self, name, value):
        self.environ[name] = value

    def get(self, name):
        return self.environ.get(name)

    def escape(self, str_):
        gtime = time.gmtime()

        self.environ['DATE'] = time.strftime("%a, %d %b %Y %H:%M:%S %Z", gtime)
        self.environ['TIME'] = time.strftime("%H:%M:%S", gtime)

        for e, v in self.environ.items():
            var = '%%%s%%' % e
            str_ = str_.replace(var, v)

        return str_
